home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / Dialog.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  6.9 KB  |  244 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Dialog.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef DIALOG_H
  11. #include "Dialog.h"
  12. #endif
  13.  
  14. #ifndef DRAWPART_H
  15. #include "DrawPart.h"
  16. #endif
  17.  
  18. #ifndef DEFINES_K
  19. #include "Defines.k"
  20. #endif
  21.  
  22. #ifndef CONTENT_H
  23. #include "Content.h"
  24. #endif
  25.  
  26. // ----- ODF Includes -----
  27.  
  28. #ifndef FWEDVIEW_H
  29. #include "FWEdView.h"
  30. #endif
  31.  
  32. #ifndef FWNOTIFN_H
  33. #include "FWNotifn.h"
  34. #endif
  35.  
  36. #ifndef FWKEYF_H
  37. #include "FWKeyF.h"
  38. #endif
  39.  
  40. #ifndef FWRESOUR_H
  41. #include "FWResour.h"
  42. #endif
  43.  
  44. #ifndef FWALERT_H
  45. #include "FWAlert.h"
  46. #endif
  47.  
  48. #ifndef SLMIXOS_H
  49. #include "SLMixOS.h"    // for FW_Beep
  50. #endif
  51.  
  52. #ifndef FWCLUSTR_H
  53. #include "FWClustr.h"
  54. #endif
  55.  
  56. //========================================================================================
  57. // Segmentation
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfdraw
  62. #endif
  63.  
  64. //========================================================================================
  65. // Static methods
  66. //========================================================================================
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // EnableDisableEditView
  70. //----------------------------------------------------------------------------------------
  71. // [HLX] Should be in the framework ??
  72.  
  73. static void EnableDisableEditView(Environment* ev, FW_CEditView* view, FW_Boolean enable)
  74. {
  75.     if (enable)
  76.     {
  77.         view->Enable(ev);
  78.         view->SelectAll(ev);
  79.     }
  80.     else
  81.     {
  82.         view->SelectText(ev, 0, 0);
  83.         view->Disable(ev);
  84.     }
  85. }
  86.  
  87. //========================================================================================
  88. // CRoundCornersDialogFrame class
  89. //========================================================================================
  90.  
  91. FW_DEFINE_AUTO(CRoundCornersDialogFrame)
  92.  
  93. //----------------------------------------------------------------------------------------
  94. // CRoundCornersDialogFrame constructor
  95. //----------------------------------------------------------------------------------------
  96.  
  97. CRoundCornersDialogFrame::CRoundCornersDialogFrame(Environment* ev, 
  98.                 ODFrame* odFrame, 
  99.                 FW_CPresentation* presentation, 
  100.                 CDrawPart* part) :
  101.     FW_CDialogFrame(ev, odFrame, presentation, part),
  102.     fDrawPart(part),
  103.     fPointsView(NULL),
  104.     fRoundEndsButton(NULL)
  105. {
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. // CRoundCornersDialogFrame destructor
  111. //----------------------------------------------------------------------------------------
  112.  
  113. CRoundCornersDialogFrame::~CRoundCornersDialogFrame()
  114. {
  115.     FW_START_DESTRUCTOR
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // CRoundCornersDialogFrame::PostCreateViewFromStream
  120. //----------------------------------------------------------------------------------------
  121.  
  122. void CRoundCornersDialogFrame::PostCreateViewFromStream(Environment* ev)
  123. {
  124.     // ----- Call inherited to propagate to all subviews if necessary
  125.     FW_CSuperView::PostCreateViewFromStream(ev);
  126.     
  127.     // ----- Find our views -----
  128.     fPointsView = (FW_CEditView*)FindViewByID(ev, kPointsID);
  129.     fRoundEndsButton = (FW_CButton*)FindViewByID(ev, kRoundEndsID);
  130.     FW_CButton* radiusButton = (FW_CButton*)FindViewByID(ev, kRadiusID);
  131.  
  132.     // ----- Create a cluster -----
  133.     FW_CRadioCluster* cluster = FW_NEW(FW_CRadioCluster, (ev));
  134.     cluster->AddRadio(ev, fRoundEndsButton);
  135.     cluster->AddRadio(ev, radiusButton);
  136.     
  137.     // ----- Initialize fields -----
  138.     FW_CString initialString;
  139.     initialString.ReplaceAllAsSignedDecimalInteger(FW_FixedToInt(fDrawPart->GetRoundRectRadius()));
  140.     fPointsView->SetText(ev, initialString);
  141.     fPointsView->SelectAll(ev);
  142.     
  143.     fPointsView->AdoptEventHandler(ev, FW_NEW(CNumberFilter, ()));
  144.     
  145.     fRoundEndsButton->SetValue(ev, fDrawPart->UseRoundEnds() ? 1 : 0);
  146.     radiusButton->SetValue(ev, fDrawPart->UseRoundEnds() ? 0 : 1);
  147.  
  148.     EnableDisableEditView(ev, fPointsView, !fDrawPart->UseRoundEnds());
  149.     
  150.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  151.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  152.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  153.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // CRoundCornersDialogFrame::HandleNotification
  158. //----------------------------------------------------------------------------------------
  159.  
  160. void CRoundCornersDialogFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  161. {
  162.     FW_Message msg = notification.GetMessage();
  163.  
  164.     switch (msg)
  165.     {
  166.         case kRoundEndsPressedMsg:
  167.         case kRadiusPressedMsg:
  168.             EnableDisableEditView(ev, fPointsView, msg == kRadiusPressedMsg);
  169.             break;
  170.         case FW_kDefaultButtonMsg:
  171.             {
  172.                 // ---- Get new settings from edit fields when clicking on Set button ----
  173.                 FW_CString str = fPointsView->GetText(ev);
  174.                 fDrawPart->ChangeRoundRectRadius(FW_IntToFixed(str.ParseAsSignedInteger()));
  175.                 
  176.                 fDrawPart->ChangeRoundEnds(fRoundEndsButton->GetValue(ev));
  177.             }
  178.             break;
  179.     }        
  180.  
  181.     // Must call inherited to close the dialog on OK & Cancel
  182.     // WARNING: do not do anything else after this call... the dialog is gone!
  183.     FW_CDialogFrame::HandleNotification(ev, notification);
  184. }
  185.  
  186. //========================================================================================
  187. // CNumberFilter class
  188. //========================================================================================
  189.  
  190. FW_DEFINE_AUTO(CNumberFilter)
  191. FW_DEFINE_CLASS_M1(CNumberFilter, FW_MEventHandler)
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CNumberFilter constructor
  195. //----------------------------------------------------------------------------------------
  196. CNumberFilter::CNumberFilter() 
  197.     : FW_MEventHandler()
  198. {
  199.     FW_END_CONSTRUCTOR
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // CNumberFilter destructor
  204. //----------------------------------------------------------------------------------------
  205. CNumberFilter::~CNumberFilter() 
  206. {
  207.     FW_START_DESTRUCTOR
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. // CNumberFilter::DoCharKeyDown
  212. //----------------------------------------------------------------------------------------
  213. FW_Handled CNumberFilter::DoCharKeyDown(Environment* ev, const FW_CCharKeyEvent& keyEvent)
  214. {
  215.     char c = keyEvent.GetChar(ev);
  216.     
  217.     // Allow backspace and arrow keys, characters 0-9 and minus sign
  218.     switch (c)
  219.     {
  220.         case 0x08:
  221.         case 0x1C:
  222.         case 0x1D:
  223.         case 0x1E:
  224.         case 0x1F:
  225.         case '0':
  226.         case '1':
  227.         case '2':
  228.         case '3':
  229.         case '4':
  230.         case '5':
  231.         case '6':
  232.         case '7':
  233.         case '8':
  234.         case '9':
  235.         case '-':
  236.             return FW_kNotHandled;
  237.     }
  238.  
  239.     // not a valid character
  240.     FW_Beep();
  241.     return FW_kHandled;
  242. }
  243.  
  244.